package com.julian.statePattern;

public class WinnerState implements State {
    GumballMachine gumballMachine;

    public WinnerState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void ejectQuarter() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void turnCrank() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void dispense() {
        if(gumballMachine.count >= 2){
            System.out.println("WINNER! ADDITONAL GUMBALL");
            gumballMachine.releaseBall();
            gumballMachine.releaseBall();
        }else {
            gumballMachine.releaseBall();
        }
        if (gumballMachine.getCount() > 0){
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        }else {
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }
}
